package com.iloomo.util;

import java.io.IOException;
import java.util.Properties;

/**
 * 获取config.properties配置文件的值
 * @author 张亚兵
 *
 */
public class ConfigUtil {

	private static Properties prop = new Properties(); 

	static { 
		   
        try { 
            prop.load(ConfigUtil.class.getClassLoader().getResourceAsStream( 
                    "config.properties"));
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
    } 
   
	public static String getEnv() {
		return (String) prop.getProperty("env").trim()+"."; 
	}
	
    public static String getValue(String key) { 
    	String envKey = getEnv() + key;
        return (String) prop.getProperty(envKey).trim(); 
    } 
    
    // 获取oss根路径配置
    public static String getOssRootDirName() { 
    	String envKey = getEnv() + "ossRootDirName";
        return (String) prop.getProperty(envKey).trim(); 
    } 
    
    // 获取oss目录配置，自动拼接根路径
    public static String getOssDirValue(String key) { 
    	String envKey = getEnv() + key;
        return getOssRootDirName() + (String) prop.getProperty(envKey).trim(); 
    } 
    
    // 获取接口域名名称
    public static String getInterfaceDomainName() { 
    	String envKey = getEnv() + "interfaceDomainName";
        return (String) prop.getProperty(envKey).trim(); 
    } 
    
    // 获取接口对应的URL全路径
    public static String getInterfaceFullUrl(String key) { 
    	String envKey = getEnv() + key;
        return getInterfaceDomainName() + (String) prop.getProperty(envKey).trim(); 
    } 
    
    // 获取H5域名名称
    public static String getH5DomainName() { 
    	String envKey = getEnv() + "h5DomainName";
        return (String) prop.getProperty(envKey).trim(); 
    } 
    
    // 获取H5对应的URL全路径
    public static String getH5FullUrl(String key) {
    	String envKey = getEnv() + key;
        return getH5DomainName() + (String) prop.getProperty(envKey).trim(); 
    } 
    
    // 获取接口域名名称
    public static String getInterfaceSslDomainName() { 
    	String envKey = getEnv() + "interfaceSslDomainName";
        return (String) prop.getProperty(envKey).trim(); 
    } 
    
    // 获取接口对应的URL全路径
    public static String getInterfaceSslFullUrl(String key) { 
    	String envKey = getEnv() + key;
        return getInterfaceSslDomainName() + (String) prop.getProperty(envKey).trim(); 
    } 
    
    // 获取商户域名名称
    public static String getShopDomainName() { 
    	String envKey = getEnv() + "shopDomainName";
        return (String) prop.getProperty(envKey).trim(); 
    } 
    
    // 获取商户对应的URL全路径
    public static String getShopFullUrl(String key) { 
    	String envKey = getEnv() + key;
        return getShopDomainName() + (String) prop.getProperty(envKey).trim(); 
    } 
}
